#include "DrawManager.hpp"

DrawManager::DrawManager(QPainter& painter, const int drawAreaWidth, const int drawAreaHeight, const int mapWidth, const int mapHeight):
    _painter(painter),
    _drawAreaWidth(drawAreaWidth),
    _drawAreaHeight(drawAreaHeight),
    _mapWidth(mapWidth),
    _mapHeight(mapHeight)
{
}

#include <iostream>

void        DrawManager::drawQuads(Map& map)
{
    QPen    pen;

    pen.setColor(Qt::gray);
    pen.setStyle(Qt::DashLine);
    _painter.setPen(pen);

    int     drawX, drawY;
    int     minX, minY;
    int     maxX, maxY;

    drawX = 0;
    minY = 0;
    maxY = (map.getHeight() - map.getPositionY()) * TILE_SIZE;
    minX = 0;
    maxX = map.getWidth() - map.getPositionX();
    while (drawX < _drawAreaWidth && minX <= maxX)
    {
        _painter.drawLine(drawX, minY, drawX, maxY);
        drawX += TILE_SIZE;
        minX++;
    }

    drawY = 0;
    minX = 0;
    maxX = (map.getWidth() - map.getPositionX()) * TILE_SIZE;
    minY = 0;
    maxY = map.getHeight() - map.getPositionY();
    while (drawY < _drawAreaHeight && minY <= maxY)
    {
        _painter.drawLine(minX, drawY, maxX, drawY);
        drawY += TILE_SIZE;
        minY++;
    }


}

void        DrawManager::drawMap(Map &map)
{
    map.draw(_painter);
}
